/*
 * Converter.java
 *
 * Created on July 11, 2007, 11:35 AM
 *
 * Copyright (C) 2007 Akhmad Fathonih (akhmadf@gmail.com)
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Changelog:
 * 2007/10/31
 * - fixed fatal flaw in subByte method
 * 2007/10/29
 * - add subByte to properly mimick subString
 */

package com.gamatechno.anybinding.util;

import gnu.crypto.util.Util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.nio.ByteBuffer;

/**
 *
 * @author geek
 */
public class Converter {
    private static int MAX_CHUNK = 16;
    
    /** Creates a new instance of Converter */
    private Converter() {
    }
    
    public static String byteToHexString(byte[] data) {
        return Util.toString(data);
//        return byteToHexString(data, true);
    }
       
    public static byte[] hexStringToByte(String data) {
        return Util.toBytesFromString(data);
    }
    
    public static byte[] subByte(byte[] source, int start, int count) {
        System.out.printf("subbyte source %d bytes from offsett %d count %d", source.length, start, count);
        ByteArrayInputStream in = new ByteArrayInputStream(source);
        byte[] bytes = new byte[count];
        in.skip(start - 1);
        in.read(bytes, 0, count);
        
        return bytes;
    }
}
